def get_weather(location: str, unit: str = "celsius") -> str:
    """
    根据地点获取天气信息
    :param location: 地点
    :param unit: 温度单位
    :return: 天气信息
    """
    return f"The weather in {location} is sunny with a temperature of 25 degrees {unit}."


def send_email(to: str, subject: str, body: str) -> str:
    """
    发送邮件
    :param to: 收件人
    :param subject: 主题
    :param body: 内容
    :return: 发送邮件的情况
    """
    return f"Email sent to {to} with subject '{subject}' and body '{body}'."


def search_knowledge_base(query: str) -> str:
    """
    根据查询条件搜索知识库
    :param query: 查询条件
    :return: 搜索结果
    """
    return f"Search results for '{query}':\n\n1. Result 1\n2. Result 2\n3. Result 3"


def create_rule(domain: str, imsi: str, operator_code: list[int], action: int = 0) -> str:
    """
    根据指定的参数信息创建规则信息，当需要创建规则时非常有用
    :param operator_code: 操作码
    :param imsi: 国际移动用户识别码
    :param domain: 目的域名
    :param action: 处置动作 默认值是0
    :return: 规则创建的情况
    """
    if action == 0:
        return f"缺少规则处置运作,不能创建规则,请提供处置运作"
    if len(domain) < 3:
        return f"缺少目的域名信息,不能创建规则,请提供目的域名"
    else:
        return f"规则已经创建好了"


create_rule_schema = {
    "name": "create_rule",
    "description": "根据指定的参数信息创建规则信息，当需要创建规则时非常有用",
    "parameters": {
        "properties": {
            "domain": {
                "description": "目的域名",
                "type": "string"
            },
            "imsi": {
                "description": "国际移动用户识别码",
                "type": "string"
            },
            "operator_code": {
                "description": "操作码",
                "items": {
                    "type": "integer"
                },
                "type": "array"
            }, "action": {
                "description": "处置动作",
                "type": "integer",
                "default": 0
            }
        },
        "required": [
            "domain",
            "imsi",
            "operator_code"
        ],
        "type": "object"
    }
}
get_weather_schema = {
    "name": "get_weather",
    "description": "根据地点获取天气信息",
    "parameters": {
        "properties": {
            "location": {
                "description": "地点",
                "type": "string"
            },
            "unit": {
                "default": "celsius",
                "description": "温度单位",
                "type": "string"
            }
        },
        "type": "object"
    }
}
search_knowledge_base_schema = {
    "name": "search_knowledge_base",
    "description": "根据查询条件搜索知识库",
    "parameters": {
        "properties": {
            "query": {
                "description": "查询条件",
                "type": "string"
            }
        },
        "required": [
            "query"
        ],
        "type": "object"
    }
}

send_email_schema = {
    "name": "send_email",
    "description": "发送邮件",
    "parameters": {
        "properties": {
            "subject": {
                "description": "主题",
                "type": "string"
            },
            "body": {
                "description": "内容",
                "type": "string"
            },
            "to": {
                "description": "收件人",
                "type": "string"
            }
        },
        "required": [
            "subject",
            "body"
        ],
        "type": "object"
    }
}

functions = {
    "get_weather": get_weather,
    "search_knowledge_base": search_knowledge_base,
    "send_email": send_email,
    "create_rule": create_rule
}


def get_function_by_name(name):
    return functions[name]
